﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class Ylt_line : MonoBehaviour
{
    
    //原理图连线
    public string[] ylt_l = { "ylt_l1", "ylt_l2", "ylt_l3", "ylt_l4", "ylt_l5" };
    public GameObject[] ylt_line=new GameObject[5];
    public CanvasGroup[] cg=new CanvasGroup[5];
    public GameObject btn_fz;
    private float timer=0.5f;
    private bool isShow = true;//用来控制闪烁的内容

    //操作提示
    private Text czts;
// Use this for initialization
    void Start () {
        //获得原理图连线ui
        //GameObject tishi = GameObject.Find("UI").transform.Find("tishi").gameObject;
        for (int i = 0; i < 5; i++)
        {
            ylt_line[i] = this.transform.Find(ylt_l[i]).gameObject;
            cg[i] = ylt_line[i].transform.GetComponent<CanvasGroup>();
        }
        //获得连线提示
        GameObject obj_czts = GameObject.Find("czts");
        czts = obj_czts.GetComponent<Text>();
    }
	
	// Update is called once per frame
	void Update () {
        if (Init.isShan)
        {
            if (Init.shanIndex< 5)
            {
                Shan(cg[Init.shanIndex]);
                if (Init.shanIndex > 0) {
                    cg[Init.shanIndex - 1].alpha = 1;
                }
            }
            else
            {
               cg[4].alpha = 1;
               Init.isShan = false;
                if (SceneManager.GetActiveScene().name == "05_exam")
                {
                   czts.text = "你的成绩为：" + Init.score + "   " + "错误次数：" + Init.errNum;
                }else if(SceneManager.GetActiveScene().name == "04_anzhuang")
                {
                    czts.text = "恭喜你完成接线练习！点击右侧仿真运行按钮查看一下成果吧！";
                    btn_fz.SetActive(true);

                }
              
            }
        }
      
    }

    //原理图提示连线顺序,闪烁
    void Shan(CanvasGroup cg)
    {
        timer -= Time.deltaTime;
        if (timer< 0&&timer>-0.5f)
        {            
            isShow = false;
        }
        else if (timer <= -0.5f)
        {
            timer = 0.5f;
            isShow = true;
        }

        if (isShow)
        {
            cg.alpha = 1;
        }
        else
        {
            cg.alpha = 0;
        }
    }



}
